package leetcode.list_problem;

/**
 * 剑指 Offer 22. 链表中倒数第k个节点
 * https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/
 */
public class GetKthFromEnd {
    public ListNode getKthFromEnd(ListNode head, int k) {//快慢指针，很有意思的解法
        ListNode fast = head;
        ListNode low = head;
        for (int i = 0; i < k; i++) {
            fast = fast.next;
        }
        while (fast != null){
            fast = fast.next;
            low = low.next;
        }
        return low;

    }
}
